/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_API_EXCEPTIONS_CUBEFS_HPP
#define	_CUBEFS_API_EXCEPTIONS_CUBEFS_HPP

#include <string>
#include <cubefs/api/types.hpp>
#include <cubefs/api/macro.hpp>

#include <stdlib.h>

//#include <stdio.h>
//#include <signal.h>
//#include <execinfo.h>

namespace cubefs    {
namespace api       {

using namespace std;

class CUBEFS_API CubefsException {
    BigInt data_;
    string source_;
    string message_;
public:
    CubefsException(const string &source, const string &message): source_(source), message_(message), data_(0) {
    	abort();
    }

    CubefsException(const string &source, const string &message, BigInt data): source_(source), message_(message), data_(data) {
    	abort();
    }

    BigInt data() const {
        return data_;
    }

    const string &source() const {
        return source_;
    }

    const string &message() const {
        return message_;
    }

//    void show_stackframe() {
//    	void *trace[16];
//    	char **messages = (char **)NULL;
//    	int i, trace_size = 0;
//
//    	trace_size = backtrace(trace, 16);
//    	messages = backtrace_symbols(trace, trace_size);
//    	printf("[bt] Execution path:\n");
//    	for (i=0; i<trace_size; ++i)
//    		printf("[bt] %s\n", messages[i]);
//    }

};


}
}
#endif //_CUBEFS_API_EXCEPTIONS_CUBEFS_HPP
